package net.huashitong.taskjob.service;

import com.sirdc.modules.sys.dao.SysDeptDao;
import com.sirdc.modules.sys.dao.SysLoginDao;
import com.sirdc.modules.sys.entity.SysDept;

import com.sirdc.modules.sys.entity.SysUser;
import com.sirdc.modules.sys.filter.SysUserFilter;
import com.sirdc.modules.sys.service.SysUserService;
import com.sirdc.modules.utils.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 督查组服务层
 */
@Service
public class SupervisionService {

    @Autowired
    private SysDeptDao sysDeptDao;
    @Autowired
    private SysLoginDao sysLoginDao;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 查询所有督查组
     * @return
     */
    public List<SysDept> queryAllSupervisions(){
        return sysDeptDao.queryWithDeptRelation("/0001/");
    }

    /**
     * 根据部门id查询用户
     * @param deptId
     * @return
     */
    public List<SysUser> querySupervisionUserByDeptId(String deptId) {
        List<SysUser> resUsers = new ArrayList<>();
        SysUserFilter filter = new SysUserFilter();
        filter.setDeptId(deptId);
        filter.setRoleId("01");
        List<String> resUser = sysLoginDao.queryLoginByRoleDept(filter);
        for (String s : resUser) {
            SysUser user = sysUserService.getById(s);
            if (ObjectUtils.isNotBlank(user)) {
                resUsers.add(user);
            }
        }
        return resUsers;
    }
}
